package com.solidumgame.martillo.score
{
	import com.pblabs.engine.PBE;
	import com.pblabs.engine.entity.EntityComponent;
	import com.solidumgame.martillo.nail.events.NailGenericEvent;
	import com.solidumgame.martillo.score.events.ScoreGenericEvent;
	
	public class ScoreLogicComponent extends EntityComponent
	{
		protected var score:uint;
		
		public function ScoreLogicComponent()
		{
			super();
			PBE.mainStage.addEventListener(NailGenericEvent.NAIL_NAILED_EVENT, updateScore);
		}
		
		protected function updateScore(e:NailGenericEvent):void{
			score+=1;
			owner.eventDispatcher.dispatchEvent(new ScoreGenericEvent(ScoreGenericEvent.SCORE_UPDATED_EVENT,score));
			PBE.mainStage.dispatchEvent(new ScoreGenericEvent(ScoreGenericEvent.SCORE_UPDATED_EVENT,score));
		}
		
		override protected function onRemove():void{
			super.onRemove();
			PBE.mainStage.removeEventListener(NailGenericEvent.NAIL_NAILED_EVENT, updateScore);
		}
	}
}